package za.co.felixsol.sf.dxf.reader.io;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import za.co.felixsol.sf.dxf.reader.DxfEntry;

public class DxfAsciiReader extends DxfReader {
	
	private InputStream dxfStream;
	private InputStreamReader dxfStreamReader;
	private BufferedReader dxfReader;
	
	public DxfAsciiReader(InputStream dxfStream) {
		this.dxfStream = dxfStream;
	}
	
	@Override
	protected DxfEntry getNextDxfEntry() throws IOException {
		String DxfEntry = dxfReader.readLine();
		String value = dxfReader.readLine();
		
//		System.out.println("DxfEntry := " + DxfEntry);
//		System.out.println("value := " + value);
		
		return new DxfEntry(DxfEntry, value);
	}

	@Override
	protected void initReader() throws IOException {
		dxfStreamReader = new InputStreamReader(dxfStream);
		dxfReader = new BufferedReader(dxfStreamReader);
	}
	
	@Override
	protected void doneReader() throws IOException {
		try { dxfReader.close(); } catch (Exception ex) {}
		try { dxfStreamReader.close(); } catch (Exception ex) {}
	}

}
